﻿/*
 * 版 本 v1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.03.22
 * 描 述：预算管理
 */
var selectedRow;
var refreshGirdData;
var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.initGrid();
            page.bind();
        },
        bind: function () {
            // 搜索框初始化
            $('#txt_Keyword').on("keypress", function (e) {
                if (event.keyCode == "13") {
                    var $this = $(this);
                    var keyword = $this.val();
                    page.search({keyword: keyword});
                }
            });
            // 查询
            $('#btn_Search').on('click', function () {
                var keyword = $('#txt_Keyword').val();
                page.search({keyword: keyword});
            });
            // 刷新
            $('#lr_refresh').on('click', function () {
                location.reload();
            });
            // 新增
            $('#lr_add').on('click', function () {
                selectedRow = null;
                learun.layerForm({
                    id: 'form',
                    title: '添加预算',
                    url: config.webportal_server + 'pages/pbd/budget/import/form.html?access_token=' + config.getToken().access_token,
                    width: 1080,
                    height: 740,
                    callBack: function (id) {
                        return top[id].acceptClick(refreshGirdData);
                    }
                });
            });
            // 编辑
            $('#lr_edit').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('id');
                selectedRow = $('#gridtable').jfGridGet('rowdata');
                if (learun.checkrow(keyValue)) {
                    learun.layerForm({
                        id: 'form',
                        title: '编辑预算',
                        url: config.webportal_server + 'pages/pbd/budget/import/form.html?access_token=' + config.getToken().access_token,
                        width: 1080,
                        height: 740,
                        callBack: function (id) {
                            return top[id].acceptClick(refreshGirdData);
                        }
                    });
                }
            });
            // 删除
            $('#lr_delete').on('click', function () {
                var keyValue = $('#gridtable').jfGridValue('id');
                if (learun.checkrow(keyValue)) {
                    learun.layerConfirm('该动作执行后此项将彻底被删除，是否确认删除该项?', function (res) {
                        if (res) {
                            learun.deleteForm(config.base_server() + 'pbdbudgets/delete/' + keyValue + '?access_token=' + config.getToken().access_token, {keyValue: keyValue}, function () {
                                refreshGirdData();
                            });
                        }
                    });
                }
            });

            // 从excel导入
            $('#lr_import').on('click', function () {
                learun.layerForm({
                    id: 'UploadifyForm',
                    title: '上传文件',
                    url: config.webportal_server + 'pages/pbd/budget/import/uploadifyForm.html?access_token=' + config.getToken().access_token,
                    width: 600,
                    height: 400,
                    callBack: function (id) {
                        return top[id].acceptClick(function (datas) {
                            if (datas) {
                                refreshGirdData();
                            }
                        });
                    }
                });
            });
            // 数据导出
            $('#lr_export').on('click', function () {
                location.href = config.base_server() + 'pbdbudgets/exportExcel?access_token=' + config.getToken().access_token;
            });
        },
        initGrid: function () {
            $('#gridtable').jfGrid({
                url: config.base_server() + 'pbdbudgets/list?access_token=' + config.getToken().access_token,
                headData: [
                    {label: '资金来源', name: 'zjly', width: 100, align: 'center'},
                    {label: '指标来源', name: 'zbly', width: 100, align: 'center'},
                    {label: '功能科目', name: 'gnflkmName', width: 100, align: 'left'},
                    {label: '部门预算经济科目', name: 'departJjkmName', width: 100, align: 'center'},
                    {label: '政府预算经济科目', name: 'govJjkmName', width: 100, align: 'center'},
                    {label: '一级项目', name: 'firstXmName', width: 100, align: 'center'},
                    {label: '项目名称', name: 'xmName', width: 100, align: 'left'},
                    {label: '项目类别', name: 'xmlbName', width: 100, align: 'center'},
                    {label: '项目类别明细', name: 'xmlbmxName', width: 100, align: 'left'},
                    {label: '预算类型', name: 'yslxName', width: 100, align: 'left'},
                    {label: '省厅下达文号', name: 'officeNumber', width: 100, align: 'left'},
                    {label: '项目标识', name: 'xmbs', width: 100, align: 'left'},
                    {
                        label: '年初预算', name: 'ncys', width: 150, align: 'left',
                        formatter: function (cellvalue) {
                            return $.formatMoney(cellvalue, 2)
                        }
                    },
                    {
                        label: '上年结转', name: 'snjz', width: 150, align: 'left',
                        formatter: function (cellvalue) {
                            return $.formatMoney(cellvalue, 2)
                        }
                    },
                    {
                        label: '年度预算', name: 'ndys', width: 150, align: 'left',
                        formatter: function (cellvalue) {
                            return $.formatMoney(cellvalue, 2)
                        }
                    },
                    {
                        label: '已下达预算数', name: 'yxdyss', width: 150, align: 'left',
                        formatter: function (cellvalue) {
                            return $.formatMoney(cellvalue, 2)
                        }
                    },
                    {
                        label: '可指出预算', name: 'kzcys', width: 150, align: 'left',
                        formatter: function (cellvalue) {
                            return $.formatMoney(cellvalue, 2)
                        }
                    },
                    {
                        label: "预算调剂、划转", name: "预算调剂、划转", width: 900, align: 'center',
                        children: [
                            {
                                label: "调增", name: "adjustAdd", width: 150, align: "right",
                                formatter: function (cellvalue) {
                                    return $.formatMoney(cellvalue, 2)
                                }
                            },
                            {
                                label: "调减", name: "adjustReduce", width: 150, align: "right",
                                formatter: function (cellvalue) {
                                    return $.formatMoney(cellvalue, 2)
                                }
                            },
                            {
                                label: "调减在途", name: "adjustReduceing", width: 150, align: "right",
                                formatter: function (cellvalue) {
                                    return $.formatMoney(cellvalue, 2)
                                }
                            },
                            {
                                label: "划入", name: "adjustIn", width: 150, align: "right",
                                formatter: function (cellvalue) {
                                    return $.formatMoney(cellvalue, 2)
                                }
                            },
                            {
                                label: "划出", name: "adjustOut", width: 150, align: "right",
                                formatter: function (cellvalue) {
                                    return $.formatMoney(cellvalue, 2)
                                }
                            },
                            {
                                label: "划出在途", name: "adjustOuting", width: 150, align: "right",
                                formatter: function (cellvalue) {
                                    return $.formatMoney(cellvalue, 2)
                                }
                            },
                        ]
                    },
                    {
                        label: "已下达计划", name: "已下达计划", width: 450, align: 'center',
                        children: [
                            {
                                label: "合计", name: "issuedTotal", width: 150, align: "right",
                                formatter: function (cellvalue) {
                                    return $.formatMoney(cellvalue, 2)
                                }
                            },
                            {
                                label: "已下达直接支付计划", name: "issuedZjzf", width: 150, align: "right",
                                formatter: function (cellvalue) {
                                    return $.formatMoney(cellvalue, 2)
                                }
                            },
                            {
                                label: "已下达授权支付计划", name: "issuedSqzf", width: 150, align: "right",
                                formatter: function (cellvalue) {
                                    return $.formatMoney(cellvalue, 2)
                                }
                            }
                        ]
                    },
                    {
                        label: '计划在途', name: 'issuedIng', width: 150, align: 'left',
                        formatter: function (cellvalue) {
                            return $.formatMoney(cellvalue, 2)
                        }
                    },
                    {
                        label: "支出", name: "支出", width: 1050, align: 'center',
                        children: [
                            {
                                label: "合计", name: "payTotal", width: 150, align: "right",
                                formatter: function (cellvalue) {
                                    return $.formatMoney(cellvalue, 2)
                                }
                            },
                            {
                                label: "直接支付", name: "payZjzf", width: 150, align: "right",
                                formatter: function (cellvalue) {
                                    return $.formatMoney(cellvalue, 2)
                                }
                            },
                            {
                                label: "授权支付", name: "paySqzf", width: 150, align: "right",
                                formatter: function (cellvalue) {
                                    return $.formatMoney(cellvalue, 2)
                                }
                            },
                            {
                                label: "统发工资支付", name: "payTfgzzf", width: 150, align: "right",
                                formatter: function (cellvalue) {
                                    return $.formatMoney(cellvalue, 2)
                                }
                            },
                            {
                                label: "一般支出", name: "payGeneral", width: 150, align: "right",
                                formatter: function (cellvalue) {
                                    return $.formatMoney(cellvalue, 2)
                                }
                            },
                            {
                                label: "补助支出", name: "payBzzc", width: 150, align: "right",
                                formatter: function (cellvalue) {
                                    return $.formatMoney(cellvalue, 2)
                                }
                            },
                            {
                                label: "列支支出", name: "payLzzc", width: 150, align: "right",
                                formatter: function (cellvalue) {
                                    return $.formatMoney(cellvalue, 2)
                                }
                            }
                        ]
                    },
                    {
                        label: '支出在途', name: 'payIng', width: 150, align: 'left',
                        formatter: function (cellvalue) {
                            return $.formatMoney(cellvalue, 2)
                        }
                    },
                    {
                        label: "更新时间", name: "updateTime", width: 140, align: "center",
                        formatter: function (value) {
                            return learun.formatDate(value, 'yyyy-MM-dd hh:mm:ss');
                        }
                    }
                ],
                dblclick: function (row) {
                    var keyValue = $('#gridtable').jfGridValue('id');
                    selectedRow = row;
                    if (learun.checkrow(keyValue)) {
                        learun.layerForm({
                            id: 'form',
                            title: '编辑预算',
                            url: config.webportal_server + 'pages/system/budget/form.html?access_token=' + config.getToken().access_token,
                            width: 1080,
                            height: 740,
                            callBack: function (id) {
                                return top[id].acceptClick(refreshGirdData);
                            }
                        });
                    }
                },
                isPage: true,
                reloadSelected: true,
                mainId: 'id'
            });

            page.search();
        },
        search: function (param) {
            param = param || {};
            $('#gridtable').jfGridSet('reload', param);
        }
    };

    refreshGirdData = function () {
        page.search();
    };

    page.init();
}


